;autoflexbuilder macros. dwerbam, 20071027

;reload actual script
;RAlt & r::Run, %A_ScriptFullPath%

;------------------------------------------------------------------ help -----
RAlt & h::
templ =
(

                    Note: you MUST BE WRITING IN flexbuilder in order to work with this keys

----------------------------------------------------- Action keys -----------------------------------------------
AltGr - h : help

AltGr - f : write function name and press action key to generate declaration
AltGr - p : write variable name and press action key to generate private declaration
AltGr - u : write variable name and press action key to generate public declaration
AltGr - g : put cursor in variable declaration's line and press action key to generate getter and setter
AltGr - n : put cursor in variable declaration's line and press action key to add [Bindable] tag
AltGr - b : build project

.for      : write abbreviation to generate a for
.result   : write abbrevation to generate a resultHandler function declaration
.fault    : write abbrevation to generate a faultHandler function declaration

)
MsgBox ,,Help,%templ%
Return

;------------------------------------------------------- macro functions -----

#IfWinActive Flex


copyClipboard() {
	Sleep 20
	clipboard =  ; Start off empty to allow ClipWait to detect when the text has arrived.
	Send ^c
	ClipWait 1
	If ErrorLevel {
		MsgBox ,,,Unable to get clipboard,3
		Return
	}
	
	Return %clipboard%
}

getVarName(vardecl) {
	RegExMatch(vardecl, "var (.*):", result)
	return result1
}

getVarType(vardecl) {
	RegExMatch(vardecl, ":(.*);", result)
	return result1	;must be result1 to point first match
}

;--------------------------------------------------------- build project -----
;Build Project, only active when Build Automatically is disabled.
RAlt & b::
Send !p{Down 2}{Enter}
Return

;----------------------------------------------------- function template -----
RAlt & f::
Send +{Home}
funcname := copyClipboard()
if !funcname
	Return

templ =
(
public function %funcname%():void 
{{}
trace("%funcname%()");
//TODO: put code here
)
SendInput %templ%
Send +{Home}
Return
;--------------------------------------------- private variable template -----
RAlt & p::
Send +{Home}
varname := copyClipboard()
if !varname
	Return

templ =
(
private var %varname%:String; 
)
SendInput %templ%
Send ^+{Left 2}
Return

;--------------------------------------------- public variable template -----
RAlt & u::
Send +{Home}
varname := copyClipboard()
if !varname
	Return

templ =
(
public var %varname%:String; 
)
SendInput %templ%
Send ^+{Left 2}
Return

;----------------------------------------------------- getter and setter -----
RAlt & g::
Send {End}
Send +{Home}
vardecl := copyClipboard()
if !vardecl
	Return

;insert a new line
Send {End}{Enter}

varname := getVarName(vardecl)
if !varname {
	MsgBox ,,,unknown variable name,3
	Return
}
vartype := getVarType(vardecl)
if !vartype {
	MsgBox ,,,unknown variable type,3
	Return
}

templ =
(
public function get %varname%():%vartype%
{{}
return this.%varname%;{Down 1}{Enter}
public function set %varname%(value:%vartype%):void
{{}
this.%varname% = value;{Down 1}{Enter}
)
SendInput %templ%
Return

;-------------------------------------------------------- [Bindable] tag -----
RAlt & n::
Send {End}{Home}{Enter}{Up}
Send [Bindable]
Send {Down}{Home}
Return

;------------------------------------------------------ for abbreviation -----
::.for:: 
templ =
(
var len:int = myArray.length;
for(var i:int=0 ; i<len ; i{+}{+})
{{}
//TODO:some code...
)
SendInput %templ%
Send +{Home}
Return

;--------------------------------------------------- result abbreviation -----
::.result::
templ =
(
public function resultHandler(ev:ResultEvent^{Space}):void 
{{}
trace("resultHandler()");
//TODO: put code here
)
SendInput %templ%
Send +{Home}
Return

;---------------------------------------------------- fault abbreviation -----
::.fault::
templ =
(
public function faultHandler(ev:FaultEvent^{Space}):void 
{{}
trace("faultHandler()");
//TODO: put code here
)
SendInput %templ%
Send +{Home}
Return

;-----------------------------------------------------------------------------

#IfWinActive


